home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8307 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  42 lines

  1. Path: magnus.acs.ohio-state.edu!news
  2. From: Angela Mallett <mallett@cfm.ohio-state.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Problem reading int from stream using fill character
  5. Date: 16 Feb 1996 18:37:58 GMT
  6. Organization: Center for Mapping
  7. Message-ID: <4g2iu6$dag@charm.magnus.acs.ohio-state.edu>
  8. NNTP-Posting-Host: nicolosi.cfm.ohio-state.edu
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.22 (Windows; I; 16bit)
  13.  
  14. I am reading formatted IO, in which a '0' character is used as a fill character
  15. to pad integers. The problem I am having is shown in the example below. I can
  16. get round the problem reading as e.g. doubles and casting, but I am interested
  17. if there is a better way. Thank you.
  18. [using Borland C++ v4.5, Windows 3.1]
  19.  
  20.  
  21. #include <strstrea.h>
  22.  
  23. int main()
  24. {
  25.     char buffer[] = {"10 09 23"};
  26.     int a=0, b=0, c=0;
  27.  
  28.     istrstream isstr(buffer);
  29.     isstr >> a >>  b  >> c;
  30.  
  31.     cout << a << ' ' << b << ' ' << c << endl;     //OUTPUT: 10 0 9!
  32.  
  33.     return 0;
  34. }
  35.  
  36. -- 
  37. Angela Mallett <mallett@cfm.ohio-state.edu>
  38. 1216 Kinnear Road, Columbus, Ohio 43212
  39. phone: 614-688-3420 fax: 614-292-8062
  40.  
  41.  
  42.